package net.uhuijia.goods.goodcategory.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


import net.uhuijia.appbase.controller.BaseController;
import net.uhuijia.constants.DBConst;
import net.uhuijia.enums.ErrorCodeEnum;
import net.uhuijia.exception.BusinessException;
import net.uhuijia.goods.goodcategory.persistence.model.GoodCategory;
import net.uhuijia.goods.goodcategory.persistence.model.GoodCategoryExample;
import net.uhuijia.goods.goodcategory.persistence.model.GoodCategoryExample.Criteria;
import net.uhuijia.goods.goodcategory.service.GoodCategoryService;
import net.uhuijia.utils.StringHelper;
import net.uhuijia.vo.ResultMapVo;
import net.uhuijia.vo.ReturnListVo;


@RestController
@RequestMapping(value="/goodcategory")
public class GoodCategoryController
     extends BaseController<GoodCategoryService,GoodCategory,GoodCategoryExample> {
	
	private GoodCategoryService goodCategoryService;
	@Autowired
	public void setUserMallService(GoodCategoryService goodCategoryService) {
		this.goodCategoryService = goodCategoryService;
	}
	
	/**
	 * 获取分类 集合 (根据父类codeId)
	 * @author 王文鑫  
	 * @date 2018年9月29日  
	 * @return
	 */
	@RequestMapping(value = "/getList", method = RequestMethod.GET)
	@ResponseBody
	public ResultMapVo<ReturnListVo<GoodCategory>> getCategoryList(String parentId) {
		
		ReturnListVo<GoodCategory> returnListVos = null;
		if(StringHelper.isEmpty(parentId)){
			throw new IllegalArgumentException();//参数异常			
		}else{
			GoodCategoryExample example = new GoodCategoryExample();
			Criteria criteria = example.createCriteria();
			criteria.andIsEffectiveEqualTo(DBConst.TRUE);
			criteria.andParentCategoryIdEqualTo(parentId);
			List<GoodCategory> goodCategoryList = goodCategoryService.list(example);
			returnListVos = new ReturnListVo<>(goodCategoryList);
		}
		
		if(returnListVos==null){
			throw new BusinessException(ErrorCodeEnum.login_error);		//业务方面的异常			
		}
		
		return ResultMapVo.ok(returnListVos);
	}
	
	
}